package com.ruoyi.dynamic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.dynamic.mapper.RoomShareRecordMapper;
import com.ruoyi.dynamic.model.pojo.entity.Room;
import com.ruoyi.dynamic.model.pojo.entity.RoomShareRecord;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomShareAddRequest;
import com.ruoyi.dynamic.service.IRoomService;
import com.ruoyi.dynamic.service.IRoomShareRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 用户分享直播间 服务实现类
 * </p>
 *
 * @author Gnc
 * @since 2025-01-11
 */
@Service
public class RoomShareRecordServiceImpl extends ServiceImpl<RoomShareRecordMapper, RoomShareRecord> implements IRoomShareRecordService {
    @Autowired
    private IRoomService iRoomService;

    @Override
    public void addRecord(Long userId, AppRoomShareAddRequest request) {
        Room verify = iRoomService.verify(request.getRoomId());
        RoomShareRecord record = new RoomShareRecord();
        record.setUserId(userId);
        record.setRoomId(request.getRoomId());
        record.setUserId(userId);
        record.setShareType(request.getShareType());
        record.setCreateTime(new Date());
        save(record);
    }

    @Override
    public boolean isShareByUser(Long roomId, Long userId) {
        return lambdaQuery().eq(RoomShareRecord::getRoomId, roomId)
                .eq(RoomShareRecord::getUserId, userId)
                .count() > 0;
    }
}
